enum DATE {

    //% block="1"
    8,
    //% block="2"
    9,
    //% block="3"
    10,
    //% block="4"
    11,
    //% block="5"
    12,
    //% block="6"
    13,
    //% block="7"
    14,
    //% block="8"
    15,
    //% block="9"
    0,
    //% block="10"
    1,
    //% block="11"
    2,
    //% block="12"
    3,
    //% block="13"
    4,
    //% block="14"
    5,
    //% block="15"
    6,
    //% block="16"
    7,
}
enum IO {
    //% block="继电器2-1"
    1,
    //% block="继电器2-2"
    2,
    //% block="继电器2-3"
    3,
    //% block="继电器2-4"
    4,
    //% block="继电器2-5"
    5,
    //% block="继电器2-6"
    6,
    //% block="继电器2-7"
    7,
    //% block="继电器1-1"
    8,
    //% block="继电器1-2"
    9,
    //% block="继电器1-3"
    10,
    //% block="继电器1-4"
    11,
    //% block="继电器1-5"
    12,
    //% block="继电器1-6"
    13,
    //% block="继电器1-7"
    14,

}
enum LEVEL{
    //% block="关"
    0,
    //% block="开"
    14,
}

enum LEN{
    //% block="1-8"
    1,
    //% block="9-16"
    2,
    //% block="全部"
    3,
}

//% color="#FFC125" iconWidth=50 iconHeight=40
namespace I2C {

    function begin() {
        Generator.addInclude('XYXKC_I2C','#include <XYXKC_I2C.h>')
        Generator.addObject('I2C_ib','XYXKC_I2C','I2C_ib;')
        Generator.addSetup('I2CSetup',`I2C_ib.begin();`)

    }
    //% block="请求一次数据" blockType="command"
    export function getRead(parameter: any, block: any) {
        begin()
        Generator.addCode(`I2C_ib.read(I2C_ib.date);`)

    }
    //% block="读取数字引脚组[LEN]" blockType="reporter"
    //% LEN.shadow="dropdown" LEN.options="LEN" LEN.defl="LEN.1"
    export function getCharData(parameter: any, block: any) {
        begin()
        let len = parameter.LEN.code;
        Generator.addCode(`I2C_ib.readString(${len})`)

    }
    //% block="读取数字引脚[DATE]" blockType="boolean"
    //% DATE.shadow="dropdown" DATE.options="DATE" DATE.defl="DATE.date[0]"
    export function date(parameter: any, block: any) {
        let I2Cdate = parameter.DATE.code;
        begin()
        Generator.addCode(`I2C_ib.date[${I2Cdate}]`)
    }

    //% block="设置[IO]状态为[LEVEL]" blockType="command"
    //% IO.shadow="dropdown" LEVEL.shadow="dropdown" IO.options="IO" LEVEL.options="LEVEL" IO.defl="IO.0" LEVEL.defl="LEVEL.0"
    export function setWrite (parameter: any, block: any) {
        let io = parameter.IO.code;
        let level = parameter.LEVEL.code;
        begin()
        Generator.addCode(`I2C_ib.write(${Number(io)+Number(level)});`)

    }
}
